﻿using System.Collections.Generic;

namespace QueryBuilder.Core.Query
{
    public class Condition : Constraint
    {
        private List<Constraint> constraints = new List<Constraint>();

        /// <summary>
        /// Initializes a new instance of the <see cref="Expression"/> class.
        /// </summary>
        /// <param name="comparisons">The comparisons.</param>
        /// <param name="constraints">The constraints.</param>
        public Condition(string comparisons, IEnumerable<Constraint> constraints)
        {
            this.Comparison = comparisons;
            this.constraints.AddRange(constraints);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Expression"/> class.
        /// </summary>
        /// <param name="comparisons">The comparisons.</param>
        /// <param name="constraint1">The constraint1.</param>
        /// <param name="constraint2">The constraint2.</param>
        public Condition(string comparisons, Constraint constraint1, Constraint constraint2)
            : this(comparisons, new List<Constraint> {constraint1, constraint2})
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Expression"/> class.
        /// </summary>
        /// <param name="comparisons">The comparisons.</param>
        /// <param name="constraint1">The constraint1.</param>
        /// <param name="constraint2">The constraint2.</param>
        /// <param name="constraint3">The constraint3.</param>
        public Condition(string comparisons, Constraint constraint1, Constraint constraint2, Constraint constraint3)
            : this(comparisons, new List<Constraint>() {constraint1, constraint2, constraint3})
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Expression"/> class.
        /// </summary>
        /// <param name="comparisons">The comparisons.</param>
        /// <param name="constraints">The constraints.</param>
        public Condition(string comparisons, params Constraint[] constraints)
            : this(comparisons, new List<Constraint>(constraints))
        {
        }

        /// <summary>
        /// Gets or sets the comparison.
        /// </summary>
        /// <value>The comparison.</value>
        public string Comparison { get; set; }

        /// <summary>
        /// Gets the constraints.
        /// </summary>
        /// <value>The constraints.</value>
        public List<Constraint> Constraints
        {
            get { return this.constraints; }
        }

        /// <summary>
        /// Accepts the specified constraint presenter.
        /// </summary>
        /// <param name="constraintPresenter">The constraint presenter.</param>
        public override void Accept(IConstraintPresenter constraintPresenter)
        {
            constraintPresenter.Present(this);
        }
    }
}